#include "BladerFactory.h"
#include "..\Components\AnimationComponent.h"
#include "..\Components\PhysicsComponent.h"
#include "..\Components\SensorComponent.h"
#include "..\Components\VisualComponent.h"
#include "..\Components\HealthComponent.h"
#include "..\Components\DamageComponent.h"
#include "..\Components\CollisionComponent.h"
#include "..\Components\FlyingAIComponent.h"
#include "..\Managers\RenderManager.h"
#include "..\Generic\MessageSystem.h"
#include <functional>


BladerFactory::BladerFactory()
{
}


BladerFactory::~BladerFactory()
{
}

GameObject* BladerFactory::createEnemy(const vn::Vector2& p_position, const std::string& p_target)
{
	std::function<void()> func = [] { MessageSystem::getSingleton().notify("kill", nullptr); };
	GameObject* go = new GameObject("blader", nullptr, nullptr);
	go->setDTorCallBack(func);
	IComponent* ic = new VisualComponent(1, "flying_enemy", 1.0f);
	go->addComponent(ic);
	ic = new AnimationComponent("animations/flying.xml", "loop");
	go->addComponent(ic);
	ic = new PhysicsComponent(b2_kinematicBody, b2Vec2(20.0f, 20.5f), b2Vec2(p_position.x, p_position.y), FIXT_ID_FLYING_ENEMY, COLLF_ENEMY, COLLF_WORLD);
	go->addComponent(ic);
	ic = new SensorComponent(FIXT_ID_ENEMY_SENSOR, b2Vec2(20.0f, 20.5f), b2Vec2(0.0f, 0.0f), 0, COLLF_ENEMY_SENSOR, COLLF_PLAYER | COLLF_PLAYER_BULLET_SENSOR);
	go->addComponent(ic);
	ic = new HealthComponent(0, 2);
	func = [=] { go->removeMe(); };
	static_cast<HealthComponent*>(ic)->setDeathCallback(func);
	go->addComponent(ic);
	ic = new DamageComponent(2);
	go->addComponent(ic);
	ic = new FlyingAIComponent(p_target);
	go->addComponent(ic);
	ic = new CollisionComponent(func, RenderManager::getSingleton().getRenderEngine()->getCamera("main"));
	go->addComponent(ic);
	go->initComponents();
	return go;
}